package com.server.web.controller.pinggu;

import com.alibaba.fastjson.JSONObject;
import com.server.common.annotation.Log;
import com.server.common.core.controller.BaseController;
import com.server.common.core.domain.AjaxResult;
import com.server.common.core.page.TableDataInfo;
import com.server.common.enums.BusinessType;
import com.server.pinggu.domain.SenForms;
import com.server.pinggu.service.ISenFormsService;
import com.server.pinggu.vo.SenFormsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ltao
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/sen/forms")
public class SenFormsController extends BaseController
{
    @Autowired
    private ISenFormsService senFormsService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SenFormsVo senForms)
    {
        startPage();
        Integer sqsjFront = null;
        Integer sqsjBack = null;
        if (senForms!=null){
            sqsjBack = senForms.getSqsjBack();
            sqsjFront = senForms.getSqsjFront();
        }
        List<SenForms> list = senFormsService.queryList(senForms,sqsjFront,sqsjBack,senForms.getStatusStr());
        return getDataTable(list);
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/queryFiltration")
    public TableDataInfo queryFiltration(@RequestParam(value = "pingname",required = false)String pingname, @RequestParam("statusStr") String statusStr)
    {
        List<JSONObject> list = senFormsService.queryFiltration(pingname,statusStr);
        return getDataTable(list);
    }
    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(senFormsService.getById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SenForms senForms)
    {
        return toAjax(senFormsService.save(senForms));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SenForms senForms)
    {
        return toAjax(senFormsService.updateById(senForms));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(senFormsService.removeByIds(Arrays.asList(ids)));
    }

    @Log(title = "【根据ID，修改图片】", businessType = BusinessType.UPDATE)
    @PostMapping("/updateImage")
    public AjaxResult remove(@RequestBody JSONObject jsonObject)
    {
        return toAjax(senFormsService.updateImageById(jsonObject));
    }
}
